import sympy as sp
def common_mistakes_demo():
    x = sp.Symbol('x')
    
    print("=== 常见错误分析 ===")
    
    # 错误1: 忘记链式法则
    print("错误1: 忘记链式法则")
    example1 = sp.sin(x**2)
    correct1 = sp.diff(example1, x)  # 2x*cos(x²)
    wrong1 = sp.cos(x**2)  # 忘记乘内层函数的导数
    
    print(f"函数: y = sin(x²)")
    print(f"正确求导: dy/dx = {correct1}")
    print(f"常见错误: dy/dx = {wrong1} (忘记了内层函数x²的导数2x)")
    print(f"避免方法: 识别复合函数，明确内外层函数关系\n")
    
    # 错误2: 乘法法则误用为导数乘积
    print("错误2: 乘法法则误用")
    example2 = x * sp.sin(x)
    correct2 = sp.diff(example2, x)  # sin(x) + x*cos(x)
    wrong2 = sp.diff(x, x) * sp.diff(sp.sin(x), x)  # 1 * cos(x) = cos(x)
    
    print(f"函数: y = x·sin(x)")
    print(f"正确求导: dy/dx = {correct2}")
    print(f"常见错误: dy/dx = {wrong2} (误以为乘积的导数等于导数的乘积)")
    print(f"避免方法: 牢记乘法法则公式 [f·g]' = f'g + fg'\n")
    
    # 错误3: 除法法则符号错误
    print("错误3: 除法法则符号错误")
    example3 = sp.sin(x) / x
    correct3 = sp.diff(example3, x)  # (x*cos(x) - sin(x)) / x²
    # 常见的符号错误：分子中误为加号
    
    print(f"函数: y = sin(x)/x")
    print(f"正确求导: dy/dx = {correct3}")
    print(f"避免方法: 牢记除法法则公式 [f/g]' = (f'g - fg')/g²，分子是减号不是加号\n")
    
    # 错误4: 反函数求导时代入错误
    print("错误4: 反函数求导错误")
    # 对于y = arcsin(x)，其导数为 1/√(1-x²)
    # 常见错误：忘记公式或错误代入
    
    print(f"函数: y = arcsin(x)")
    print(f"正确导数: dy/dx = 1/√(1-x²)")
    print(f"避免方法: 理解反函数求导原理，或直接记忆常见反函数导数公式")

common_mistakes_demo()